<template>
	<view class="color333 mine">
		<view class="bgBox">
			<view class="bg">
				<image class="" src="https://aihelp.oss-cn-hangzhou.aliyuncs.com/kwkd/resources/personal/defaultBg.jpg"
					mode="widthFix"></image>
			</view>
			<view class="info">
				<!-- 个人信息 -->
				<view class="alignCenter flex">
					<view class="avater" @click.stop="changeAva">
						<image class=""
							:src="userInfo.avatar || 'https://image.alhelp.net/uploads/20231104/4d491857ac50d21ebbcb25ff5bc254f8.png'"
							mode="widthFix"></image>
					</view>
					<view class="">
						<view class="bold font16 login" v-if="!isLogin" @click.stop="login">立即登录</view>
						<view class="" v-if="isLogin">
							<view class="bold font16 nickName">{{ userInfo.nickName || '匿名用户' }}</view>
							<view class="color666 font12 intro hiddenOneline">{{ userInfo.introduction || '这个人很懒，还什么都没有写~' }}</view>
						</view>
					</view>
				</view>
				<uni-icons class="set" type="gear" size="30" @click="toSetting"></uni-icons>
				<view v-if="false" class="w-100 flex align-center VipBox u-p-l-40 u-p-r-40 u-font-28">
					<view>开通VIP,享受更多权限</view>
					<view class="btn">
						<uni-icons type="vip-filled" size="20" color="#f9e541" class="u-m-r-5"></uni-icons>
						开通
					</view>
				</view>
			</view>
		</view>
		<view class="color333 u-p-l-40 u-p-r-40 u-p-t-70">
			<u-row :gutter="40">
				<u-col :span="6" v-for="(item,index) in itemArr" :key="index">
					<view class="flex align-center justify-center u-font-26 items bg-white" @click="itemClick(item,index)">
						<u-icon class="u-m-r-10" :name="item.icon" size="48"></u-icon>
						{{item.title}}
					</view>
				</u-col>
			</u-row>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo,
		wxgetAgent
	} from "@/api/mine.js"
	import {
		getNoRead,
		navigateLoginPage
	} from "@/utils/common.js"
	export default {
		data() {
			return {
				isLogin: false,
				itemArr: [{
						title: '钱包',
						url: '/pages/mine/wallet/wallet',
						icon: 'https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/12/15/be96390ad59d4ffc931fef2b94cfdc57.png'
					},
					{
						title: '问题反馈',
						icon: 'https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/12/15/1d6777f7f9eb4978816cbd9405a52049.png',
						url: '/pages/mine/feedback/feedback'
					},
					{
						title: '关于我们',
						icon: "https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/12/15/9403ff859be94413a5331b3a923cd31a.png",
						url: '/pages/mine/aboutUs/aboutUs'
					},
				],
				userInfo: '',
			};
		},
		onShow() {
			this.getUser()
			this.isLogin = uni.getStorageSync('token') ? true : false
			// #ifndef MP
			// #endif
			if (!this.isLogin) {
				return
			}
			// #ifdef MP-WEIXIN
			if (this.checkeMenuItem('/pages/message/message')) {
				this.itemArr.splice(1, 0, {
					title: '我的消息',
					rightType: '',
					url: '/pages/message/message',
					icon: 'https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/12/15/4f2d4ec8abb942c9a941bda3bf90fb74.png'
				})
			}
			// 获取未读消息
			if (!uni.getStorageSync('token')) return;
			getNoRead((num) => {
				if (num > 0) {
					this.itemArr.forEach((valItem) => {
						if (valItem.title == '我的消息') {
							valItem.rightType = 'redDot'
						} else {
							valItem.rightType = ''
						}
					})
				} else {
					this.itemArr.forEach((valItem) => {
						if (valItem.title == '我的消息') {
							valItem.rightType = ''
						}
					})
				}
			})
			// #endif
		},
		methods: {
			checkeMenuItem(url) {
				let checked = true
				this.itemArr.forEach(item => {
					if (item.url === url) {
						checked = false
					}
				})
				return checked
			},

			async getAgent() {
				const res = await wxgetAgent();
				let arr = ['flowBottom', 'experience', 'corporateAccount', 'flowerAdmin', 'flower', 'flowAdmin', 'flow',
					'schoolExtend'
				];
				for (let i = 0; i < res.roles.length; i++) {
					if (arr.includes(res.roles[i])) {
						if (this.checkeMenuItem('/pages/mine/extend/extend')) {
							this.itemArr.unshift({
								title: '推广列表',
								rightType: '',
								icon: 'https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/12/17/c7c357f14c9842bdbf6d63dfef693edc.png',
								url: '/pages/mine/extend/extend',
							})
							break;
						}
					}
				}
			},
			login() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			// 获取用户信息
			getUser() {
				if (!uni.getStorageSync('userId')) return;
				getUserInfo({
					userId: uni.getStorageSync('userId')
				}).then((res) => {
					if (res.code == 100000) {
						uni.setStorageSync('userInfo', res.data)
						this.userInfo = res.data
						this.getAgent()
					}
				})
			},
			// 列表功能的点击事件
			itemClick(item, index) {
				const title = item.title
				const url = item.url
				if (title.indexOf('我们') != -1) {
					uni.navigateTo({
						url: '/pages/mine/aboutUs/aboutUs'
					})
					return
				}
				if (!this.isLogin) {
					navigateLoginPage('noJump')
					return
				}
				uni.navigateTo({
					url
				})
			},
			// 粉丝/关注的点击事件
			handleClick(type) {
				if (type == 'fan') {
					uni.navigateTo({
						url: '/pages/mine/fan/fan'
					})
					return
				} else if (type == 'focus') {
					uni.navigateTo({
						url: '/pages/mine/focus/focus'
					})
					return
				} else if (type == 'group') {
					uni.navigateTo({
						url: '/pages/mine/group/group'
					})
					return
				} else if (type == 'activity') {
					uni.navigateTo({
						url: '/pages/send/activity/activity'
					})
					return
				}
			},
			// 设置
			toSetting() {
				if (!this.isLogin) {
					navigateLoginPage('noJump')
					return
				}
				uni.navigateTo({
					url: '/settingPages/pages/setting'
				})
			},
			// 改头像
			changeAva() {
				if (!this.isLogin) {
					navigateLoginPage('noJump')
					return
				}
				uni.navigateTo({
					url: '/settingPages/pages/setting'
				})
			},
			toHomePage() {
				if (!this.isLogin) {
					navigateLoginPage('noJump')
					return
				}
				uni.navigateTo({
					url: '/pages/mine/homePage/homePage'
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	@import "@/static/public.scss";

	.mine {
		background-color: #F8F9FC;
		min-height: 100vh;
		width: 100%;
	}

	.bgBox {
		height: 536rpx;
		position: relative;

		.bg {
			width: 100%;
			height: 100%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.info {
			position: absolute;
			top: 0;
			left: 0;
			/* #ifdef APP-PLUS */
			padding: 110rpx 50rpx 0;
			/* #endif */
			/* #ifdef MP-WEIXIN */
			padding: 150rpx 50rpx 0;
			/* #endif */
			/* #ifdef H5 */
			padding: 60rpx 50rpx 0;
			/* #endif */
			width: 100%;
			height: 100%;
			box-sizing: border-box;
			background: rgba(255, 255, 255, .8);

			.avater {
				width: 156rpx;
				height: 156rpx;
				border-radius: 50%;
				margin-right: 20rpx;
				border: 8rpx solid #ebeeef;
				box-sizing: border-box;
				flex-shrink: 0;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.fan {
				text {
					display: inline-block;
					margin-right: 18rpx;
				}
			}

			.actAndGroup {
				margin: 30rpx 0 0;
				padding: 0 30rpx;
				box-sizing: border-box;

				image {
					width: 48rpx;
					height: 48rpx;
					margin: 0 10rpx 0 0;
				}
			}

			.set {
				position: absolute;
				right: 50rpx;
				/* #ifdef APP-PLUS */
				top: 100rpx;
				/* #endif */
				/* #ifdef MP-WEIXIN */
				top: 150rpx;
				/* #endif */
				/* #ifdef H5 */
				top: 40rpx;
				/* #endif */
			}

			.intro {
				margin: 24rpx 0;
			}
		}
	}

	.menu {
		position: absolute;
		padding: 0 30rpx;
		width: 100%;
		box-sizing: border-box;
		z-index: 10;
		bottom: -100rpx;

		.menuMain {
			border-radius: 68rpx 68rpx 6rpx 6rpx;
			box-shadow: 6rpx 6rpx 6px rgba(153, 153, 153, .35);
			border-radius: 20rpx;

			.vip {
				background: #fff;
				padding: 40rpx 20rpx;
				border-radius: 68rpx 68rpx 0 0;
				box-sizing: border-box;
			}

			.openVipStyle {
				margin: 0 0 0 10rpx;
			}

			.menuBox {
				background: #fff;
				padding: 30rpx 58rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
			}

			.menuItem {
				text-align: center;

				i {
					font-size: 70rpx;
				}

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}

	.itemBox {
		.hasPadding {
			padding: 0 30rpx;

			::v-deep .listItem {
				padding: 30rpx 0;
			}
		}

		.slogan {
			text-align: center;
			padding: 60rpx 0 50rpx;
			border-top: 10rpx solid #F8F9FC;
			border-bottom: 20rpx solid #F8F9FC;
		}
	}

	.items {
		height: 134rpx;
		border-radius: 10rpx;
		box-shadow: 10rpx 10rpx 10rpx #F2F2F2;
		margin-bottom: 40rpx;
	}

	.VipBox {
		height: 116rpx;
		border-radius: 100rpx;
		background-color: #fff;
		margin-top: 60rpx;

		.btn {
			width: 176rpx;
			height: 64rpx;
			background-color: #FFCC00;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 100rpx;
			margin-left: auto;
		}
	}
</style>